<template>
  <div class="hello">
    <h1>{{ msg }}</h1>
    <a-input
      placeholder="请输入任务"
      :value="inputValue"
      @change="handleInputChange"
      class="my_ipt"
    />
    <a-button type="primary" @click="addItemToList">添加事项</a-button>

    <a-list bordered :dataSource="infoList" class="dt_list">
      <a-list-item slot="renderItem" slot-scope="item">
        <!-- 复选框 -->
        <a-checkbox
          :checked="item.done"
          @change="cbStatusChanged($event, item.id)"
          >{{ item.info }}</a-checkbox
        >
        <!-- 删除链接 -->
        <a slot="actions" @click="removeItemById(item.id)">删除</a>
      </a-list-item>

      <!-- footer区域 -->
      <div slot="footer" class="footer">
        <!-- 未完成的任务个数 -->
        <span>{{ unDoneLength }}条剩余</span>
        <!-- 操作按钮 -->
        <a-button-group>
          <a-button :type="viewKey == 'all' ? 'primary':'default'" @click="changeList('all')">全部</a-button>
          <a-button :type="viewKey == 'undone' ? 'primary':'default'" @click="changeList('undone')">未完成</a-button>
          <a-button :type="viewKey == 'done' ? 'primary':'default'" @click="changeList('done')">已完成</a-button>
        </a-button-group>
        <!-- 把已经完成的任务清空 -->
        <a @click="clear">清除已完成</a>
      </div>
    </a-list>

  </div>
</template>

<script>
import { mapState, mapGetters } from 'vuex'


// 2. 导入组件库的样式表
import 'ant-design-vue/dist/antd.css'

export default {
  name: 'HelloWorld',
  props: {
    msg: String
  },

  created:function(){
    this.$store.dispatch('getList')
  },

  data:function(){
    return  {
    inputValue:''
    }
  },
  computed: {
    ...mapState(['list','viewKey']),
    ...mapGetters(['unDoneLength','infoList'])
  },
  methods:{
    clear:function(){
      this.$store.dispatch('clearDone');
    },
    handleInputChange:function(e){
      this.inputValue = e.target.value;
    },
    cbStatusChanged:function(){

    },
    removeItemById:function(){

    },
    changeList:function(value){
        this.$store.commit('changeList',value);
    },
    addItemToList:function(){
      console.log('inputValue='+this.inputValue);
      this.$store.commit('addItemToList',this.inputValue);
     // this.inputValue = '';

    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
  #app {
    padding: 10px;
  }

  .my_ipt {
    width: 500px;
    margin-right: 10px;
  }

  .dt_list {
    width: 500px;
    margin-top: 10px;
  }

  .footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
</style>
